package com.itheima.exam.config;

import com.itheima.exam.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pages/**").addResourceLocations("classpath:/pages/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //需要放行
        ArrayList<String> acl = new ArrayList();
        acl.add("/pages/**");
        acl.add("/user/login");
        //配置拦截器
        registry.addInterceptor(loginInterceptor)
                //拦截
                .addPathPatterns("/**")
                //放行
                .excludePathPatterns(acl);
    }
}
